//
//  AppDelegate.m
//  Alltelevisionnews
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"



@interface AppDelegate ()<WXApiDelegate, TencentSessionDelegate, WeiboSDKDelegate>
@property(nonatomic, strong) UIImageView *imageView;

@end

@implementation AppDelegate
{
    TencentOAuth *_tencentOAuth;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];   //设置通用背景颜色
    [self.window makeKeyAndVisible];
    
    
     [WXApi registerApp:@"wx0b3030afb3978bfb"];
    // 开始网络状态监控
    [SLAFNetWorkTool startMonitorNet];
    
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLauched"];
        [self createData];
        
        self.imageView = [[UIImageView alloc] init];
        [self.window addSubview:self.imageView];
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.and.left.and.bottom.and.right.equalTo(self.window).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
            
        }];
        
        NSMutableArray *picArray = [NSMutableArray array];
        for (NSInteger i = 1; i < 104; i++) {
            NSString *imageName = [NSString stringWithFormat:@"p%ld.png", i];
            NSLog(@"%@", imageName);
            UIImage *image = [UIImage imageNamed:imageName];
            
            [picArray addObject:image];
            
        }
        
        self.imageView.animationImages = picArray;
        self.imageView.animationDuration = 7;
        self.imageView.animationRepeatCount = 1;
        
        [self.imageView startAnimating];
        
    } else {
//
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLauched"];
        [self createData];
        
        
    }
    

    
    return YES;
}


#pragma mark首页方法
- (void)createData {
    
    ViewController *view = [[ViewController alloc] init];
    self.mainNavigationController = [[UINavigationController alloc] initWithRootViewController:view];
    
    LeftPageViewController *leftVC = [[LeftPageViewController alloc] init];
    self.leftslideVC = [[LeftSlideViewController alloc] initWithLeftView:leftVC andMainView:self.mainNavigationController];
    self.window.rootViewController = self.leftslideVC;
    self.mainNavigationController.navigationBar.barTintColor = [UIColor blackColor];
    

    /////微信
     [WXApi registerApp:@"wx0b3030afb3978bfb"];
    
    // QQ
    _tencentOAuth = [[TencentOAuth alloc] initWithAppId:@"1104928563"  andDelegate:self];
    //新浪微博
    [WeiboSDK registerApp:@"257601427"];
    
    // 开始网络状态监控
    [SLAFNetWorkTool startMonitorNet];

    
}


////微信/QQ/微博 跳转
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return  [WXApi handleOpenURL:url delegate:self];
    return [TencentOAuth HandleOpenURL:url];
    return [WeiboSDK handleOpenURL:url delegate:self];
    
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [WXApi handleOpenURL:url delegate:self];
    return [TencentOAuth HandleOpenURL:url];
    return [WeiboSDK handleOpenURL:url delegate:self];
}


- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    
    
    
    return UIInterfaceOrientationMaskPortrait;
    
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
